<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { queryEnumType } from "@/api/common.js";
import { formatData } from "@/utils/formatData.js";
const $props = defineProps(["type", "list"]);
const $emits = defineEmits(["IdChange"]);
const selectCode = ref();
let EnumTypeList = reactive([]);
onMounted(() => {
  getTagEnumType($props.type);
});

const getTagEnumType = async (type) => {
  const res = await queryEnumType({ type });
  EnumTypeList = Object.assign(EnumTypeList, res.data);
  console.log(EnumTypeList, "enum");
};

const handleChangeTag = (enumCode) => {
  console.log(enumCode);
  $emits("IdChange", enumCode);
  selectCode.value = enumCode;
};
</script>

<template>
  <div class="container">
    <header>
      目前共计{{ EnumTypeList.length }}个{{
        type === "cate-type" ? "分类" : "标签"
      }},继续加油
    </header>
    <div class="left">
      <div class="line-items">
        <div
          class="item"
          v-for="item in EnumTypeList"
          :key="item.id"
          @click="handleChangeTag(item.enumCode)"
          :class="{ active: item.enumCode === selectCode ? true : false }"
        >
          <span>{{ item.enumText }}</span>
        </div>
      </div>
    </div>
    <div class="right">
      <el-timeline>
        <el-timeline-item
          placement="top"
          v-for="(item, index) in list"
          :key="item.id"
          :timestamp="formatData(item.createTime)"
        >
          <el-card>
            <h4>{{ item.title }}</h4>
            <div class="info">
              <div class="pic">
                <img :src="item.authorInfo.avatar" alt="" />
              </div>
              <div class="name">
                {{ item.authorInfo.nickname }}
              </div>
              <el-tag v-if="item.typeId">{{ item.typeInfo.typeName }}</el-tag>
              <el-tag v-for="tag in item.tagList" v-if="item.tagsId" :key="tag.id">{{
                tag.tagName
              }}</el-tag>
            </div>
          </el-card>
        </el-timeline-item>
      </el-timeline>
      <p>我也是有底线的~~~</p>
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  margin: 0 auto;
  margin-top: 20px;
  width: 70%;
  height: 100%;
  header {
    padding: 10px;
    border-bottom: 2px solid #e4e7ed;
    text-align: center;
    font-weight: bold;
    color: $strong;
  }
  .left {
    margin-top: 20px;
    float: left;
    width: 17%;
    .line-items {
      font-size: 14px;
      .item {
        cursor: pointer;
        &.active {
          color: $strong;
        }
        &:hover {
          color: $strong;
          &::before {
            left: 13px;
            width: 14px;
            height: 14px;
          }
        }
        &:last-child {
          &::after {
            width: 0;
            height: 0;
          }
        }
        padding-left: 30px;
        position: relative;
        height: 40px;
        span {
          margin-left: 10px;
        }
        &::before {
          content: "";
          position: absolute;
          top: 5px;
          left: 15px;
          width: 11px;
          height: 11px;
          border-radius: 50%;
          background: $strong;
          transition: all 0.2s ease;
          z-index: 2;
        }
        &::after {
          content: "";
          position: absolute;
          left: 18px;
          top: 6px;
          width: 4px;
          height: 100%;
          background: $strong;
        }
      }
    }
  }
  .right {
    max-height: 600px;
    overflow: auto;
    width: 80%;
    margin-top: 20px;
    float: left;
    .info {
      margin-top: 20px;
      color: $strong;
      display: flex;
      align-items: end;
      .pic {
        width: 40px;
        height: 40px;
        overflow: hidden;
        border: 1px solid $strong;
        border-radius: 50%;
        img {
          width: 100%;
        }
      }
      .name {
        font-weight: 600;
        margin-bottom: 4px;
        margin-left: 10px;
      }
      .el-tag {
        margin-left: 15px;
      }
    }
    p {
      text-align: center;
    }
  }
}
@media screen and (max-width: 1000px) {
  .container {
    width: 100%;
    padding: 0 10px;
  }
}
</style>
